/* 
 * File:   StrategyCodec.h
 * Author: root
 *
 * Created on November 22, 2008, 6:13 PM
 */

#ifndef _STRATEGYCODEC_H
#define	_STRATEGYCODEC_H

#include "Strategy.h"
#include "StrategyGene.h"

enum StrategyType {KNOCKING, DRAWING, DISCARD, END_DRAW, END_DISCARD};

// Number of implemented strategies of each type (increment each time a new strategy is added)
const int AVAILABLE_STRATEGIES[3] = {7, 6, 6};  
// Repeated here; needed for class array initializations
const int AVAILABLE_KNOCKING = 7;
const int AVAILABLE_DRAWING = 6;
const int AVAILABLE_DISCARD = 6;

class StrategyCodec {
    
    Strategy** strategyRegistry[3];
                                 
    void fillRegistry();
    
public:
    
    StrategyCodec() {
        for (int i = KNOCKING; i <= DISCARD; i++) {
            strategyRegistry[i] = new Strategy*[AVAILABLE_STRATEGIES[i]];
        }
        fillRegistry();
    }
    
    StrategyGene* encode(StrategyType, int) const;   // Encodes the ith registered strategy of the given type
//    StrategyGene* encodePredefined(StrategyType, int, int) const; // Encodes the ith registered strategy of the given type with the jth predefined configuration
    Strategy* decode(StrategyType, StrategyGene*) const;    // Returns a new instance of the strategy given by the gene
    
    ~StrategyCodec() {
        for (int i = KNOCKING; i <= DISCARD; i++) {
            for (int j = 0; j < AVAILABLE_STRATEGIES[i]; j++) {
                delete strategyRegistry[i][j];
            }
            delete []strategyRegistry[i];
        }
    }
};

#endif	/* _STRATEGYCODEC_H */

